package br.org.etec.dotcao.dao.jpa;

import java.util.Collections;
import java.util.List;

import javax.persistence.TypedQuery;

import br.org.etec.dotcao.dao.StateDao;
import br.org.etec.dotcao.model.State;

public class StateDaoImpl extends JPAImpl<State> implements StateDao {

	public StateDaoImpl() {
		super(State.class);
	}

	@Override
	public List<State> all(String name) {
		TypedQuery<State> query = em.createNamedQuery("stateByName", State.class);
		query.setParameter("name", name + "%");
		
		try {
			return query.getResultList();
		} catch (Exception e) {
			e.printStackTrace();
			return Collections.emptyList();
		} 
		
	}

}
